package Example.immutable;

import com.google.common.collect.Maps;
import annoations.ThreadSafe;

import java.util.Collections;
import java.util.Map;

/**
 * 使用JDK下Collections下un...开头的方法，使Map的值不可以再改变
 *
 * @author Wang Renlei
 * @Date 2020/7/2
 */
@ThreadSafe
public class ImmutableExample2 {

    private static Map<Integer, Integer> map = Maps.newHashMap();

    static {
        map.put(1, 2);
        map.put(3, 4);
        map.put(5, 6);
        map = Collections.unmodifiableMap(map);
    }

    public static void main(String[] args) {
//        map.put(1, 3);
        System.out.println(map.get(1));
    }

}
